package com.cyufeng.blog.controller;

import com.cyufeng.blog.dto.AccountDto;
import com.cyufeng.blog.dto.ArticleDto;
import com.cyufeng.blog.dto.SensitiveDto;
import com.cyufeng.blog.entity.Sensitive;
import com.cyufeng.blog.service.ArticleSerivce;
import com.cyufeng.blog.service.SensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 敏感词
 * @author Cyufeng
 * Data:2019.03.21
 */
@CrossOrigin
@RequestMapping("/blog/sensitive")
@RestController
public class SensitiveController {
    @Autowired
    SensitiveService sensitiveService;

    /**
     * 保存关键词
     * @return
     */
    @GetMapping("/saveSensitive")
    public void saveSensitive(@RequestParam(value = "word") String word){
        sensitiveService.saveSensitive(word);
    }

    /**
     * 分页得到所有关键词-用于后台管理
     * @param page
     * @param size
     * 2019.3.22
     * @return
     */
    @GetMapping("/getAllSensitive")
    public Map<String, Object> getAllSensitive(@RequestParam(value = "page") Integer page, @RequestParam(value = "size") Integer size){
        return sensitiveService.getAllSensitive(page,size);
    }

    /**
     * 改变是否启用
     *
     * @return
     */
    @GetMapping("/setIsEnable")
    public String setIsEnable(@RequestParam("isEnable") Boolean isEnable, @RequestParam("id") int id) {
        return sensitiveService.setIsEnbale(isEnable, id);
    }

    /**
     * 保存修改
     *
     * @return
     */
    @GetMapping("/saveEdit")
    public String setIsEnable(@RequestParam("newWord") String newWord, @RequestParam("id") int id) {

        return sensitiveService.saveEdit(newWord, id);
    }

    /**
     * 删除敏感词
     *
     * @return
     */
    @GetMapping("/deleteWord")
    public String deleteWord(@RequestParam("id") int id) {

        return sensitiveService.deleteWord(id);
    }

    /**
     * 保存新敏感词
     *
     * @return
     */
    @GetMapping("/saveWord")
    public String saveWord(@RequestParam("newWord") String newWord) {
        return sensitiveService.saveSensitive(newWord);
    }

}
